//
//  RankingListCollectionViewCell.m
//  YanMusicPlayer
//
//  Created by 1564335 on 15-6-13.
//  Copyright (c) 2015年 胡岩 All rights reserved.
//

#import "RankingListCollectionViewCell.h"

@interface RankingListCollectionViewCell ()

@property(nonatomic, strong) UIImageView *bgImageView;
@property(nonatomic, strong) UIButton *startBtn;
@property(nonatomic, strong) UILabel *rankName;
@property(nonatomic, strong) UILabel *firstSongName;
@property(nonatomic, strong) UILabel *firstSingerName;
@property(nonatomic, strong) UILabel *secondSongName;
@property(nonatomic, strong) UILabel *secondSingerName;
@property(nonatomic, strong) UILabel *thirdSongName;
@property(nonatomic, strong) UILabel *thirdSingerName;

@end

@implementation RankingListCollectionViewCell

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        _bgImageView = [[UIImageView alloc] init];
        _startBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        _rankName = [[UILabel alloc] init];
        _firstSingerName = [[UILabel alloc] init];
        _firstSongName = [[UILabel alloc] init];
        _secondSingerName = [[UILabel alloc] init];
        _secondSongName = [[UILabel alloc] init];
        _thirdSingerName = [[UILabel alloc] init];
        _thirdSongName = [[UILabel alloc] init];
        
        [self.contentView addSubview:_bgImageView];
//        [_bgImageView addSubview:_startBtn];
        [_bgImageView addSubview:_rankName];
        [self.contentView addSubview:_firstSongName];
        [self.contentView addSubview:_firstSingerName];
        [self.contentView addSubview:_secondSongName];
        [self.contentView addSubview:_secondSingerName];
        [self.contentView addSubview:_thirdSongName];
        [self.contentView addSubview:_thirdSingerName];
    }
    return self;
}

- (void)setRankingListViewModel:(RankingListViewModel *)rankingListViewModel
{
    _rankingListViewModel = rankingListViewModel;
    [_bgImageView setImageWithURL:[NSURL URLWithString:_rankingListViewModel.pic_url] placeholderImage:[UIImage imageNamed:@"bgImage3"]];
    _rankName.text = _rankingListViewModel.title;
    for (int i = 0; i < 3; i++) {
        if (_rankingListViewModel.songList.count > i) {
            RankingListViewSongListModel *songListModel = [_rankingListViewModel.songList objectAtIndex:i];
            if (i == 0) {
                _firstSingerName.text = songListModel.singerName;
                _firstSongName.text = songListModel.songName;
            } else if (i == 1) {
                _secondSingerName.text = songListModel.singerName;
                _secondSongName.text = songListModel.songName;
            } else if (i == 2) {
                _thirdSingerName.text = songListModel.singerName;
                _thirdSongName.text = songListModel.songName;
            }
        }
    }
    
}

- (void)layoutSubviews
{
    [super layoutSubviews];
    _bgImageView.frame = CGRectMake(0, 0, self.frame.size.width, self.frame.size.height / 2);
    _bgImageView.layer.cornerRadius = 5;
    _bgImageView.layer.masksToBounds = YES;
    
    _startBtn.frame = CGRectMake(0, 0, 40, 40);
    _startBtn.center = _bgImageView.center;
    _startBtn.backgroundColor = [UIColor grayColor];
    _startBtn.layer.cornerRadius = 20;
    _startBtn.layer.masksToBounds = YES;
    _startBtn.alpha = 0.5;
    
    _rankName.frame = CGRectMake(0, _bgImageView.frame.size.height - 25, _bgImageView.frame.size.width, 25);
    _rankName.backgroundColor = [UIColor blackColor];
    _rankName.textColor = [UIColor whiteColor];
    _rankName.alpha = 0.7;
    _rankName.font = [UIFont systemFontOfSize:13];
    
    
    CGFloat songNameHeigth = (self.frame.size.height / 2 - 30) / 3 * 2 / 3;
    CGFloat singerNameHeight = (self.frame.size.height / 2 - 30) / 3 / 3;
    _firstSongName.frame = CGRectMake(0, self.frame.size.height / 2 + 5, self.frame.size.width, songNameHeigth);
    _firstSingerName.frame = CGRectMake(0, _firstSongName.frame.origin.y + _firstSongName.frame.size.height + 5, self.frame.size.width, singerNameHeight);
    
    _secondSongName.frame = CGRectMake(0, _firstSingerName.frame.origin.y + _firstSingerName.frame.size.height + 5, self.frame.size.width, songNameHeigth);
    _secondSingerName.frame = CGRectMake(0, _secondSongName.frame.origin.y + _secondSongName.frame.size.height + 5, self.frame.size.width, singerNameHeight);
    
    _thirdSongName.frame = CGRectMake(0, _secondSingerName.frame.origin.y + _secondSingerName.frame.size.height + 5, self.frame.size.width, songNameHeigth);
    _thirdSingerName.frame = CGRectMake(0, _thirdSongName.frame.origin.y + _thirdSongName.frame.size.height + 4, self.frame.size.width, singerNameHeight);
 
    _firstSingerName.textColor = [UIColor blackColor];
    _firstSongName.textColor = [UIColor blackColor];
    _secondSongName.textColor = [UIColor blackColor];
    _secondSingerName.textColor = [UIColor blackColor];
    _thirdSongName.textColor = [UIColor blackColor];
    _thirdSingerName.textColor = [UIColor blackColor];
    
    _secondSongName.font = [UIFont systemFontOfSize:14 * (_HEIGHT / _DEFAULT_HEIGHT)];
    _secondSingerName.font = [UIFont systemFontOfSize:9 * (_HEIGHT / _DEFAULT_HEIGHT)];
    _firstSongName.font = [UIFont systemFontOfSize:14 * (_HEIGHT / _DEFAULT_HEIGHT)];
    _firstSingerName.font = [UIFont systemFontOfSize:9 * (_HEIGHT / _DEFAULT_HEIGHT)];
    _thirdSongName.font = [UIFont systemFontOfSize:14 * (_HEIGHT / _DEFAULT_HEIGHT)];
    _thirdSingerName.font = [UIFont systemFontOfSize:9 * (_HEIGHT / _DEFAULT_HEIGHT)];
    
}







@end
